<template>
  <div>
    <div class="div_cls">
      <div>
        <div class="div_cls_A">
          <input type="text" placeholder="回车搜索商品" />
        </div>
        <div class="div_clst">
          <div class="div_c1">
            <ul>
              <li
                v-for="(item, index) in oiderlist"
                :key="index"
                class="li_cls"
                @click="addleft(item.id)"
              >
                {{ item.name }}
              </li>
            </ul>
          </div>

          <div class="div_cl2">
            <van-swipe
              class="my-swipe"
              :autoplay="3000"
              indicator-color="white"
            >
              <van-swipe-item>
                <img src="../assets/17.png" width="400px" class="img_cls" />
              </van-swipe-item>
              <van-swipe-item>
                <img src="../assets/16.png" width="400px" class="img_cls" />
              </van-swipe-item>
              <van-swipe-item>
                <img src="../assets/15.png" width="400px" class="img_cls" />
              </van-swipe-item>
            </van-swipe>
            <!-- 轮播 -->
            <!-- 居家 -->
            <ul class="ul_clstion">
              <li
                v-for="(item, index) in rightlist"
                :key="index"
                @click="fenlei(item)"
              >
                <img :src="item.icon" />
                <p>{{ item.name }}</p>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      goodslist: [],
      oiderlist: [],
      rightlist: [],
    };
  },
  mounted() {
    this.$APL.GOODSPOST().then((res) => {
      console.log(res.data.data);
      this.goodslist = res.data.data;
      //左边导航栏
      this.oiderlist.push({ name: "所有分类", id: "als" });
      this.goodslist.forEach((res) => {
        if (res.pid == 0) {
          this.oiderlist.push(res);
        } else {
          this.rightlist.push(res);
        }
      });
    });
  },
  methods: {
    addleft(id) {
      console.log(id);
      this.rightlist = [];
      this.goodslist.forEach((res) => {
        if (id == res.pid) {
          this.rightlist.push(res);
        } else if (id == "als") {
          this.rightlist.push(res);
        }
      });
    },
    //分类
    fenlei(item) {
      this.$router.push({ 
        path: "/editlist",
         query: { 
           id:item.id
          } 
        });
    },
  },
};
</script>
<style lang="scss">
.div_cls {
  height: 90vh;
  //   background: red;
}
.div_cls_A {
  width: 100%;
  border-bottom: 1px solid gainsboro;
  input {
    margin: 0.2rem;
    height: 0.4rem;
    border-radius: 0.2rem;
    border: 0;
    background: rgb(245, 240, 240);
    padding-left: 0.2rem;
  }
}
.div_clst {
  width: 100%;
  //   background: lavenderblush;
  display: flex;
}
.div_c1 {
  width: 20%;
  height: 11.5rem;
  border-right: 1px solid gainsboro;
  overflow: scroll;
  li {
    width: 100%;
    border-right: 1px solid gainsboro;
    height: 0.8rem;
    line-height: 0.8rem;
    text-align: center;
    font-size: 0.3rem;
    &:hover {
      color: red;
      border-left: 2px solid lightcoral;
    }
  }
}
.div_cl2 {
  width: 80%;
  z-index: 9999;
  height: 11rem;
  overflow: scroll;
}
.img_cls {
  width: 5rem;
  text-align: center;
  margin: 0.5rem;
}
.ul_clstion {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  li {
    width: 30%;
    text-align: center;
    img {
      width: 2rem;
    }
  }
}
</style>